package com.tanhua.dubbo.server.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.common.exception.BusinessException;
import com.tanhua.common.vo.ErrorResult;
import com.tanhua.dubbo.server.enums.CommentPublishIdType;
import com.tanhua.dubbo.server.service.QuanZiService;
import com.tanhua.dubbo.server.vo.PageResult;
import com.tanhua.dubbo.server.vo.QuanZiVo;
import com.tanhua.dubbo.server.vo.VisitorsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName: QuanZiController
 * @Author:王晨晗
 * @Description: 圈子控制层
 * @Date: 2021/12/30/21:43
 */
@RestController
@RequestMapping("/movements")
public class QuanZiController {
    @Autowired
    private QuanZiService quanZiService;

    /**
     * @description 查询好友动态
     * @param page
     * @param pagesize
     * @updateTime 2021/12/30 21:46
     * @return: org.springframework.http.ResponseEntity
     */
    @GetMapping
    public ResponseEntity queryPublishList(Integer page , Integer pagesize){
        PageResult result = quanZiService.queryPublishList(page , pagesize);
        return ResponseEntity.ok(result);
    }


    /**
     * @description 推荐动态
     * @param page
     * @param pagesize
     * @updateTime 2021/12/30 23:11
     */
    @GetMapping("recommend")
    public ResponseEntity queryRecomendPublishList(Integer page , Integer pagesize){
        PageResult result = quanZiService.queryRecomendPublishList(page , pagesize);
        return ResponseEntity.ok(result);
    }


    /**
     * @description 发布动态
     * @param textContent 文字内容
     * @param multipartFiles 图片数组
     * @param location   位置
     * @param longitude  经度
     * @param latitude   维度
     * @updateTime 2021/12/31 10:02
     */
    @PostMapping
    public ResponseEntity savePublish(
            @RequestParam("textContent") String textContent,
            @RequestParam(value = "imageContent" , required = false) MultipartFile[] multipartFiles,
            @RequestParam(value = "location" , required = false) String location,
            @RequestParam(value = "longitude" , required = false) String longitude,
            @RequestParam(value = "latitude" , required = false) String latitude){
        String s = quanZiService.savePublish(textContent, multipartFiles, location, longitude, latitude);
        return ResponseEntity.ok(s);
    }

    /**
     * @description 动态的点赞功能
     * @param publishId 动态的id
     * @return 返回该动态的点赞数
     */
    @GetMapping("/{id}/like")
    public ResponseEntity<Long> likeComment(@PathVariable("id") String publishId){
        Long likeCount = quanZiService.likeComment(publishId , CommentPublishIdType.PUBLISH);  //指明对动态的点赞
        return ResponseEntity.ok(likeCount);
    }

    /**
     * @description 动态的取消点赞功能
     * @param publishId 动态的id
     * @return 返回该动态的点赞数
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity<Long> disLikeComment(@PathVariable("id") String publishId){
        Long likeCount = quanZiService.disLikeComment(publishId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * @description 动态的喜欢功能
     * @param publishId 动态的id
     * @return 返回该动态的喜欢数
     */
    @GetMapping("/{id}/love")
    public ResponseEntity<Long> loveComment(@PathVariable("id") String publishId) {
        Long loveCount = quanZiService.loveComment(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * @description 动态的取消喜欢功能
     * @param publishId 动态的id
     * @return 返回该动态的喜欢数
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity<Long> disLoveComment(@PathVariable("id") String publishId) {
        Long loveCount = quanZiService.disLoveComment(publishId);
        return ResponseEntity.ok(loveCount);
    }

    /**
     * @description 查询单条动态信息
     * @param publishId
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<QuanZiVo> queryById(@PathVariable("id") String publishId) {
        QuanZiVo movements = quanZiService.queryById(publishId);
        return ResponseEntity.ok(movements);
    }

    /**
     * @description 查询个人的所有动态
     * @param page
     * @param pageSize
     * @param userId
     * @return
     */
    @GetMapping("all")
    public ResponseEntity queryAlbumList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                                     @RequestParam(value = "userId") Long userId) {
        PageResult pageResult = quanZiService.queryAlbumList(userId , page , pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * @description 谁看过我功能
     * @return
     */
    @GetMapping("visitors")
    public ResponseEntity<Object> queryVisitors() {
        List<VisitorsVo> list = quanZiService.queryVisitorList();
        return ResponseEntity.ok(list);
    }

}
